package com.example.administrator.mydagger2.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.example.administrator.mydagger2.App;
import com.example.administrator.mydagger2.R;
import com.example.administrator.mydagger2.modle.Apple;

import javax.inject.Inject;

public class MainActivity extends AppCompatActivity {
    @Inject//Inject在需要依赖的的地方互相使用这个注解
    public Apple apple;//不能使用私有修饰

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //有参数传输需要使用builder().*moduleName*(new ModuleName("白色")).build().Inject(this)创建,实例化 apple
        //DaggerAppleComponent.builder().appleModule(new AppleModule("白色")).build().Inject(this);
       // DaggerAppleComponent.create().Inject(this);

        ((App) getApplication()).getAppleComponent().Inject(this);//自定义注解需拿到我们自定义Application
        apple.orange();
        apple.dagger("榴莲");
        Log.i("luohao", "onCreate:MainActivity" + apple);
        this.findViewById(R.id.mBT_activity1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, Main2Activity.class));
            }
        });
    }
}
